package io;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class ReaderDemo {

    public static void main(String[] args) {
        try(Reader reader=new FileReader("./test.txt")) {
            char[] buffer=new char[1024];
            int n=reader.read(buffer);//返回值表示读取到的字符数量
            if(n==-1) return;
            System.out.println(n);
            for(int i=0;i<n;i++) {
                System.out.print(buffer[i]);
            }
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
    public static void main1(String[] args) {
        try(Reader reader=new FileReader("./test.txt")) {
            while(true) {
                int c = reader.read();//返回值仍是int,范围是0~65535
                if (c == -1) break;//返回-1表示结尾
                System.out.println((char) c);
            }
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
}
